/*
  Copyright © 2010  Vinícius dos Santos Oliveira

      This file is part of Touché.

      Touché is free software: you can redistribute it and/or modify
      it under the terms of the GNU Lesser General Public License as published
      by the Free Software Foundation, either version 3 of the License, or
      (at your option) any later version.

      This program is distributed in the hope that it will be useful,
      but WITHOUT ANY WARRANTY; without even the implied warranty of
      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      GNU Lesser General Public License for more details.

      You should have received a copy of the GNU Lesser General Public License
      along with this program.  If not, see <http://www.gnu.org/licenses/>.
  */

#ifndef SCRIBBLEAREAITEM_H
#define SCRIBBLEAREAITEM_H

#include "imageitem.h"
#include <QPainter>

class ScribbleAreaItem : public ImageItem
{
    Q_OBJECT

    QImage *paintDevice;
    QPen pen;
    QPainter *painter;
    bool scribbling;
    QPointF lastPoint;
    bool m_null;

protected:
    virtual void mousePressEvent(QGraphicsSceneMouseEvent *event);
    virtual void mouseMoveEvent(QGraphicsSceneMouseEvent *event);
    virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent *event);

public:
    ScribbleAreaItem(QImage *, QGraphicsItem *parentItem = 0);
    ~ScribbleAreaItem();
    bool openImage(const QString &fileName);
    bool saveImage(const QString &fileName, const char *format = "png");
    void setPen(const QPen &pen);
    void setCompositionMode(QPainter::CompositionMode mode = QPainter::CompositionMode_SourceOver);
    bool isNull();

public slots:
    void clearImage();
};

inline bool ScribbleAreaItem::isNull()
{
    return m_null;
}

#endif // SCRIBBLEAREAITEM_H
